//
//  AdWebViewController.m
//  SP2P
//
//  Created by EIMS-IOS on 14-9-29.
//  Copyright (c) 2014年 EIMS. All rights reserved.
//

#import "AdWebViewController.h"

@interface AdWebViewController ()<UIWebViewDelegate>
@property (nonatomic, strong) UIActivityIndicatorView *activity;
@end

@implementation AdWebViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 初始化视图
    [self initView];
   
}


#pragma mark ------webview代理
-(void)webViewDidStartLoad:(UIWebView *)webView {
    [_activity startAnimating];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    [_activity stopAnimating];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    [_activity stopAnimating];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

/**
 初始化数据
 */
- (void)initView
{
    
    [self initNavigationBar];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    UIWebView *adWebView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:_urlStr]];
    [adWebView loadRequest:request];
    adWebView.scalesPageToFit =YES;
    [adWebView setUserInteractionEnabled:YES];
    adWebView.delegate = self;
    [self.view addSubview:adWebView];
    
    _activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _activity.center = adWebView.center;
    [self.view addSubview:_activity];
    
    
}

/**
 * 初始化导航条
 */
- (void)initNavigationBar
{
    [self initNavBarTitle:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] andLeftItemName:@"返回" andRightItemName:@""];

}


#pragma 返回按钮触发方法
- (void)back
{
    // DLOG(@"返回按钮");
    [self.navigationController popViewControllerAnimated:YES];
    
    
}


@end
